<?php 
namespace Home\Controller;
use Think\Controller;
/**
* 激活
*/
class ActivateController extends CommonController
{
	public function index()
	{
		$rec=D('user')->where("id='$_SESSION[id]'")->select();
		$rec=current($rec);
		$this->assign('arr',$rec);
		$this->display();
	}
	public function txd()
	{
		$sql = "select email from user where id={$_SESSION['id']}";

		$res=M('user')->field('email')->where("id='$_SESSION[id]'")->select();
		$email=current($res);
		$email=$email['email'];
		$mail=md5($email);
		$id=dechex($_SESSION['id']);
		$check= $mail.'&m_acd='.$id;
		// var_dump($email);
		// exit;
		$url="http://127.0.0.1/Bbs/index.php/home/activate/check/?token=".$check;
				       
		$title=<<<ct
		<table style="width: 600px; border: 1px solid #ddd; border-radius: 3px; color: #555; font-family: 'Helvetica Neue Regular',Helvetica,Arial,Tahoma,'Microsoft YaHei','San Francisco','微软雅黑','Hiragino Sans GB',STHeitiSC-Light; font-size: 12px; height: auto; margin: auto; overflow: hidden; text-align: left; word-break: break-all; word-wrap: break-word;" cellspacing="0" cellpadding="0" border="0">
		 	<tbody style="margin: 0; padding: 0;">
			    <tr style="background-color: #393D49; height: 60px; margin: 0; padding: 0;">
			        <td style="margin: 0; padding: 0;">
				        <div style="color: #5EB576; margin: 0; margin-left: 30px; padding: 0;">
				          <a style="font-size: 14px; margin: 0; padding: 0; color: #5EB576; text-decoration: none;" href="http://fly.layui.com/" target="_blank">这是一个流氓社区</a>
				        </div>
			        </td>
			    </tr>
			    <tr style="margin: 0; padding: 0;">
			      	<td style="margin: 0; padding: 30px;">
				        <p style="line-height: 20px; margin: 0; margin-bottom: 10px; padding: 0;">Hi，
				          <em style="font-weight: 700;">%s</em>，请完成以下操作：</p>
				        <div style="">
				          <a href="http://{$_SERVER['HTTP_HOST']}/Bbs/index.php/home/activate/check/?token=%s" style="background-color: #009E94; color: #fff; display: inline-block; height: 32px; line-height: 32px; margin: 0 15px 0 0; padding: 0 15px; text-decoration: none;" target="_blank">立即激活邮箱</a>
				        </div>
				        <p style="line-height: 20px; margin-top: 20px; padding: 10px; background-color: #f2f2f2; font-size: 12px;">如果该邮件不是由你本人操作，请勿进行激活！否则你的邮箱将会被他人绑定。
				        </p>
				    </td>
		    	</tr>
			    <tr style="background-color: #fafafa; color: #999; height: 35px; margin: 0; padding: 0; text-align: center;">
			      <td style="margin: 0; padding: 0;">系统邮件，请勿直接回复。</td>
			    </tr>
		  	</tbody>
		</table>
ct;
		$title=sprintf($title,$_SESSION['nikename'],$check);
		$str="这是一个流氓软件";

		$res = qqemail($email,$str,$title);
		if($res){
			header("Location:".U('home/activate/index'));
			echo json_encode(123);
		}

	}
	public function check()
	{
		$data=$_GET['token'];
		$id =hexdec($_GET['m_acd']);
		$rec=M('user')->where("id='$id'")->select();

			$rec=current($rec);
			$token=md5($rec['email']);
			if ($data==$token) {
				$sql="update user set act='1' where id ={$_SESSION['id']}";

				// var_dump($sql);
				// UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
				M('user')->where("id='$id'")->save(array('act'=>'1'));
					$_SESSION['nikename']=$rec['nikename'];
					$_SESSION['id']=$id;
					$_SESSION['face']=$rec['face'];
				header("Location:".U('home/activate/index'));
			}else{
				$this->error('非法操作',U('home/index/index'),3);
			}	
	}

}
?>